package com.pentofab.payrollmanagement.dao.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;

import com.pentofab.payrollmanagement.application.PayrollApplicationFactory;
import com.pentofab.payrollmanagement.dao.SalaryDAO;
import com.pentofab.payrollmanagement.dao.model.Employee;
import com.pentofab.payrollmanagement.dao.model.EsiPfBonus;
import com.pentofab.payrollmanagement.dao.model.Holiday;
import com.pentofab.payrollmanagement.dao.model.PTSlab;
import com.pentofab.payrollmanagement.dao.model.SalaryAdvance;
import com.pentofab.payrollmanagement.dao.model.SalaryProfile;
import com.pentofab.payrollmanagement.dao.model.SalaryStracture;
import com.pentofab.payrollmanagement.database.AttendanceRepository;
import com.pentofab.payrollmanagement.database.EmployeeRepository;
import com.pentofab.payrollmanagement.database.LeaveRepository;
import com.pentofab.payrollmanagement.database.SalaryRepository;
import com.pentofab.payrollmanagement.database.impl.AttendanceRepositoryImpl;
import com.pentofab.payrollmanagement.database.impl.EmployeeRepositoryImpl;
import com.pentofab.payrollmanagement.database.impl.LeaveRepositoryImpl;
import com.pentofab.payrollmanagement.database.impl.SalaryRepositoryimpl;
import com.pentofab.payrollmanagement.exception.BusinessException;
import com.pentofab.payrollmanagement.utilities.CustomTableConstants;
import com.pentofab.payrollmanagement.utilities.PayRollUtility;

public class SalaryDAOImpl implements SalaryDAO {
	
	private SalaryRepository salaryRepository;
	private AttendanceRepository attendanceRepository;
	private LeaveRepository leaveRepository;
	private EmployeeRepository employeeRepository;
	public SalaryDAOImpl(){
		
		salaryRepository = new SalaryRepositoryimpl();
		attendanceRepository = new AttendanceRepositoryImpl();
		leaveRepository = new LeaveRepositoryImpl();
		employeeRepository = new EmployeeRepositoryImpl();
	}
	
	public ArrayList<SalaryProfile> getSalaryProfiles() throws BusinessException{
		try{
			
			return salaryRepository.getSalaryProfiles();
		}catch(Exception e){
			
			throw new BusinessException(e,"Error while getting salary profile.");
		}
	
	}

	@Override
	public void addSalaryProfile(SalaryProfile salaryProfile)
			throws BusinessException {
		
		try{
			
			 salaryRepository.addSalaryProfile(salaryProfile);                                                     
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
		
	}

	@Override
	public void modifySalaryProfile(SalaryProfile salaryProfile)
			throws BusinessException {
		try{
			
			 salaryRepository.modifySalaryProfile(salaryProfile);                                                     
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void deleteSalaryProfile(String profieName) throws BusinessException {
		
		try{
			
			 salaryRepository.deleteSalaryProfile(profieName);                                 
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public ArrayList<SalaryAdvance> getSalaryAdvance(String empId) throws BusinessException {
		
		try{
			
			return salaryRepository.getSalaryAdvance(empId);                            
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	
	}

	@Override
	public void appliForAdvance(SalaryAdvance salaryAdvance)
			throws BusinessException {
		
		try{
			
			 salaryRepository.appliForAdvance(salaryAdvance);                                                     
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
		
	}

	@Override
	public void deleteSalaryAdvance(String empId, int rowNum)
			throws BusinessException {
		try{
			
			 salaryRepository.deleteSalaryAdvance(empId, rowNum);                             
		}catch(Exception e){
			
			throw new BusinessException(e,"Errow hile deletig salary advance");
		}
	}

	@Override
	public ArrayList<PTSlab> getPTSlab() throws BusinessException {
		
		try{
			
			 return salaryRepository.getPTSlab();          
		}catch(Exception e){
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void addPTSlab(String ptTaxAmount, String maxLimit) throws BusinessException {
		
		try{
			
			 salaryRepository.addPTSlab(ptTaxAmount, maxLimit);   
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void updatePTSlab(String ptTaxAmount, String maxLimit)
			throws BusinessException {
		
		try{
			
			 salaryRepository.updatePTSlab(ptTaxAmount, maxLimit);   
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void deletePTSlab(String maxLimit) throws BusinessException {
		
		try{
			
			 salaryRepository.deletePTSlab(maxLimit);
		}catch(Exception e){
			
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public ArrayList<String> getAllEmpSalaryStracture()
			throws BusinessException {
		try {
			
			return salaryRepository.getAllEmpSalaryStracture();
		} catch (Exception e) {
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public SalaryStracture getSalaryStractureForEmp(String empId)
			throws BusinessException {
		
		try {
			return salaryRepository.getSalaryStractureForEmp(empId);
		} catch (Exception e) {
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void insertSalaryStracture(SalaryStracture salaryStracture)
			throws BusinessException {
		
		try {
			 salaryRepository.insertSalaryStracture(salaryStracture);
		} catch (Exception e) {
			throw new BusinessException(e,e.getMessage());
		}
	}

	@Override
	public void updateSalaryStracture(SalaryStracture salaryStracture)
			throws BusinessException {
		
		try {
			 
			salaryRepository.updateSalaryStracture(salaryStracture);
			 
		} catch (Exception e) {
			throw new BusinessException(e,e.getMessage());
		}
	}

	public ArrayList<HashMap<String, String>> getSalaryReport(String employeeId,String selyear,int selectedMonths)
			throws BusinessException {
		
		try {

			ArrayList<HashMap<String, String>> salaryInfoList = salaryRepository.getSalaryReport(employeeId);

			int maxDay  = PayRollUtility.getMaxDayofMonth(Integer.parseInt(selyear), selectedMonths);
			String from_date = "01-"+(selectedMonths+1)+"-"+selyear;
			String to_date = maxDay+"-"+(selectedMonths+1)+"-"+selyear;

			ArrayList<HashMap<String,String>> attDetailList = PayrollApplicationFactory.getAttandanceMgmt().
					employeeTimesheetInfo(null, null, null, from_date, to_date,"", 1);
			HashMap<String, String> empInfoDataMap = new HashMap<String, String>();
	        HashMap<String, HashMap<String, String>> attLeaveHolidayInfoMap = new HashMap<String, HashMap<String, String>>();
	        
	        HashMap<String , Integer> empWeekOffInfo = new HashMap<String, Integer>();
	        HashMap<String, String> hoursPerDayMap =new HashMap<String, String>();
	        ArrayList<Holiday> holidayDataListFromDB = PayrollApplicationFactory.getLeaveDAO().getHolidays();
	        
	        ArrayList<String> holidayList =new ArrayList<String>();
	        
	        for(int i = 0;i< holidayDataListFromDB.size();i++){
	        	holidayList.add(holidayDataListFromDB.get(i).getDate());
	        }
	        
	        LinkedHashSet<String> daysOfMontSet = PayRollUtility.getDatesForMonth(maxDay, from_date);
	        HashMap<String, String> totalWorkHours = new HashMap<String, String>();

			LeaveModuleUtility.megeAttLevHoliData(attDetailList, empInfoDataMap, attLeaveHolidayInfoMap, 
					empWeekOffInfo, holidayList, totalWorkHours, hoursPerDayMap, daysOfMontSet);
			
			System.out.println("totalWorkHours : "+totalWorkHours);
			System.out.println("salaryInfoList : "+salaryInfoList);
			Iterator<HashMap<String, String>> salaryInfoListiIterator = salaryInfoList.listIterator();
			
			ArrayList<HashMap<String, String>> removeList =  new ArrayList<HashMap<String,String>>();
			while(salaryInfoListiIterator.hasNext()){
				
				HashMap<String, String> curHashMap = salaryInfoListiIterator.next();
				String empId = curHashMap.get("EMPID");
				
				/*if(!hoursPerDayMap.containsKey(empId)){
					removeList.add(curHashMap);
					continue;
				}*/
				//INCENTIVE
				String padiDays =  totalWorkHours.get(empId);
				String actualWorkHrs =  totalWorkHours.get(empId);
				String totalWOrkHrs = null;
				double grossSal =  Double.parseDouble(curHashMap.get("GROSS"));
				double oneDaySal = grossSal/maxDay;
				
				double lop = 0.0;
				double incentive = 0.0;
				if(hoursPerDayMap.get(empId) == null){
					
					
					int paidDaysCount = Integer.parseInt(padiDays);
					if(maxDay > paidDaysCount){
						
						lop = (maxDay -paidDaysCount) * oneDaySal;
					}
					
					if(maxDay < paidDaysCount){
						
						incentive = (paidDaysCount - maxDay) * oneDaySal;
						padiDays = String.valueOf(maxDay);
					}
				}else{
					String hoursPerDay = hoursPerDayMap.get(empId);
					int workedMins = 0;
					String[] timeSheet = actualWorkHrs.split(":");
					workedMins = Integer.parseInt(timeSheet[0]) *60;
					workedMins = workedMins + Integer.parseInt(timeSheet[1]);
					
					int requmins = 0;
					String[] reuMin = hoursPerDay.split(":");
					requmins = Integer.parseInt(reuMin[0]) *60*maxDay;
					requmins = requmins + Integer.parseInt(reuMin[1]);
					
					String[] hoursPerDayArry = hoursPerDay.split(":");
					double perHr =  (grossSal/maxDay) /( (Double.parseDouble(hoursPerDayArry[0]))+(Double.parseDouble(hoursPerDayArry[1])/60));
					
					if(workedMins > requmins){
						
						int extra = requmins - workedMins;
						incentive = 	perHr*(extra/60);
						
						padiDays = String.valueOf(requmins);
					}else{
						int less = workedMins -  requmins;
						lop = perHr*(less/60);
					}
				}
				
				curHashMap.put("PAIDDAYS",padiDays);
				curHashMap.put("MaxDays", String.valueOf(maxDay));
				curHashMap.put("INCENTIVE", PayRollUtility.decilamFormat(String.valueOf(incentive)));
				curHashMap.put("LOP", String.valueOf(lop));
				double earnings = Double.parseDouble(curHashMap.get("Earnings"));
				earnings = earnings+incentive;
				curHashMap.put("Earnings",earnings+"");
				double pt = salaryRepository.getPT(String.valueOf(earnings));
				double deductions = Double.parseDouble(curHashMap.get("DECUCATION"));
				deductions = deductions+lop+Double.valueOf(pt);
				curHashMap.put("DECUCATION",PayRollUtility.decilamFormat(deductions+""));
				curHashMap.put("PROTax",pt+"");
				curHashMap.put("NetPay",PayRollUtility.decilamFormat((earnings - deductions)+""));
			}
			
//			salaryInfoList.removeAll(removeList);
			return salaryInfoList;

		} catch (Exception e) {
			e.printStackTrace();
			throw new BusinessException(e,e.getMessage());
		}
	}
	
	public EsiPfBonus getEsiPfBonus() throws BusinessException{
		
		try{
			
			return salaryRepository.getEsiPfBonus();
		}catch(Exception e){
			throw new BusinessException(e,e.getMessage());
		}
	}
	public void setEsiPfBonus(EsiPfBonus esiPfBonus) throws BusinessException{
		
		try{
			
			salaryRepository.setEsiPfBonus(esiPfBonus);
		}catch(Exception e){
			throw new BusinessException(e,e.getMessage());
		}
	}

	
	public HashMap<String, SalaryStracture> computeSalaryForMonth(String startDate,String endDate,String empId,String company,String unit,String dept,String selyear, 
			int selectedMonths) throws Exception{

		HashMap<String, SalaryStracture> empSalStr = new HashMap<String, SalaryStracture>();
		int maxDay  = PayRollUtility.getMaxDayofMonth(Integer.parseInt(selyear), selectedMonths);
		ArrayList<HashMap<String,String>> monthlyReport = attendanceRepository.employeeTimesheetInfo(empId, company, dept, startDate, endDate,unit, 2);
		EsiPfBonus esiPfBonus = salaryRepository.getEsiPfBonus();

		System.out.println("monthlyReport : "+monthlyReport);
		ArrayList<Holiday> holidayList = leaveRepository.getHolidays();

		ArrayList<String> nationalHolidayList = new ArrayList<String>();
		ArrayList<String> generalHolidayList = new ArrayList<String>();

		Iterator<Holiday> holidayListIterator = holidayList.iterator();
		while(holidayListIterator.hasNext()){
			Holiday holiday = holidayListIterator.next();

			if(holiday.isNationalHoliday()){

				nationalHolidayList.add(holiday.getDate());
			}else{
				generalHolidayList.add(holiday.getDate());
			}
		}

		if(monthlyReport != null && monthlyReport.size() > 0){

			Iterator<HashMap<String,String>> monthlyReportIterator = monthlyReport.iterator();

			while(monthlyReportIterator.hasNext()){
				HashMap<String,String> workingInfo = new HashMap<String,String>();
				LinkedHashSet<String> daysOfMontSet = PayRollUtility.getDatesForMonth(maxDay, startDate); 
				System.out.println("daysOfMontSet : "+daysOfMontSet);
				HashMap<String,String> curEmpAttRep = monthlyReportIterator.next();
				String curEmpID = curEmpAttRep.get(CustomTableConstants.EMPI);


				System.out.println("curEmpAttRep : "+curEmpAttRep);
				Employee curEmp = employeeRepository.getEmpById(curEmpID);
				System.out.println("curEmp : "+curEmp);
				SalaryStracture salaryStracture = salaryRepository.getSalaryStractureForEmp(curEmpID);


				System.out.println("salaryStracture : "+salaryStracture);
				if(salaryStracture == null){
					continue;
				}
				ArrayList<HashMap<String,String>> dailyReport = attendanceRepository.employeeTimesheetInfo(curEmpID, company, dept, startDate, endDate,unit, 1);
				HashMap<String,HashMap<String, String>> dayliAttMap = new  HashMap<String,HashMap<String, String>> ();
				Iterator<HashMap<String, String>> iterator = dailyReport.iterator();

				while(iterator.hasNext()){
					HashMap<String, String> cur = iterator.next();
					dayliAttMap.put(cur.get(CustomTableConstants.attDate), cur);
				}
				System.out.println("dayliAttMap : "+dayliAttMap);
				Iterator<String> daysIterator = daysOfMontSet.iterator();
				String wekOff = curEmp.getWeeklyOff();
				String hrsPerDay = curEmp.getHoursperday();
				String total = curEmpAttRep.get(CustomTableConstants.total);
				double noOfDays = 0;
				while(daysIterator.hasNext()){

					String curDate = daysIterator.next();
					Calendar cal = Calendar.getInstance();
					cal.setTime(PayRollUtility.convertStringToDate(curDate));
					int weekOfDay = cal.get(Calendar.DAY_OF_WEEK);
					int empWeekOffDay = -1;

					if (!wekOff.equals("")) {

						empWeekOffDay = PayRollUtility.dayOfWeek(wekOff);
					}

					boolean empOnLeave = leaveRepository.empOnLeave(curEmpID, curDate);

					if(curEmp.getCategory() != null && curEmp.getCategory().getCode() != null && 
							curEmp.getCategory().getCode().equalsIgnoreCase("DA")){

						if(empOnLeave){

							if(dayliAttMap.containsKey(curDate)){

								String time[]  = hrsPerDay.split(":");
								int hrs = Integer.parseInt(time[0]);
								int mins = Integer.parseInt(time[1]);
								if(hrs > 0 )
									hrs = hrs/2;

								if(mins > 0 )
									mins = mins/2;

								total = PayRollUtility.addTime(total, hrs+":"+mins);
							}else{

								total = PayRollUtility.addTime(total, hrsPerDay);
							}
						}

						if(nationalHolidayList.contains(curDate) ){

							total = PayRollUtility.addTime(total, hrsPerDay);
						}

						if(generalHolidayList.contains(curDate) && 
								(dayliAttMap.containsKey(PayRollUtility.getNextOrPrevDate(curDate, true, false))) && 
								dayliAttMap.containsKey(PayRollUtility.getNextOrPrevDate(curDate, false, true))){

							total = PayRollUtility.addTime(total, hrsPerDay);
						}

						if(weekOfDay == empWeekOffDay){

							System.out.println("total :"+total);
							System.out.println("hrsPerDay :"+hrsPerDay);
							total = PayRollUtility.addTime(total, hrsPerDay);
						}
						workingInfo.put(curEmpID, total);

					}else{
						if(empOnLeave){

							if(dayliAttMap.containsKey(curDate)){

								noOfDays = noOfDays+0.5;
							}else{

								noOfDays = noOfDays+1;
							}
						}
						if(nationalHolidayList.contains(curDate)){

							noOfDays = noOfDays+1;
						}
						if(generalHolidayList.contains(curDate) && 
								(dayliAttMap.containsKey(PayRollUtility.getNextOrPrevDate(curDate, true, false))) && 
								dayliAttMap.containsKey(PayRollUtility.getNextOrPrevDate(curDate, false, true))){

							noOfDays = noOfDays+1;
						}

						if(weekOfDay == empWeekOffDay){

							noOfDays = noOfDays+1;
						}

						if(!empOnLeave && dayliAttMap.containsKey(curDate)){

							noOfDays = noOfDays+1;
						}
						workingInfo.put(curEmpID, noOfDays+"");
					}
				}

				System.out.println("workingInfo : "+workingInfo);
				double paidDays = 0;
				double incentiveDays = 0;
				double lopDays = 0;

				if(noOfDays == 0){
					//daily basis employee
					maxDay =26;
					String workedHrs = workingInfo.get(curEmpID);
					String[] workedHrsArray = workedHrs.split(":");
					int totahHrs = Integer.parseInt(workedHrsArray[0]);
					int totalMins = Integer.parseInt(workedHrsArray[0]);
					totalMins = totalMins+(totahHrs*60);
					String time[]  = hrsPerDay.split(":");
					int hrs = Integer.parseInt(time[0]);
					int mins = Integer.parseInt(time[1]);
					int reqMins = 26*hrs*60+mins;

					int diffMins = totalMins - reqMins;

					if(diffMins > 0){
						//Incentive
						paidDays = 26;
						int incMin = diffMins%60;
						int incHrs = diffMins/60;

						if(incMin > 30)
							incHrs++;
						incentiveDays = incHrs/hrs;

					}else{

						diffMins = diffMins*-1;
						int lopMins = diffMins%60;
						int lopHrs = diffMins/60;

						if(lopMins > 30)
							lopHrs++;
						lopDays = lopHrs/hrs;
						//LOP

						paidDays = 26 - lopDays;
					}

				}else{


					paidDays = Double.parseDouble(maxDay+"");
					if(noOfDays > paidDays){

						incentiveDays = noOfDays - paidDays;
					}else{
						lopDays = paidDays - noOfDays;
						paidDays = paidDays - lopDays;
					}
				}
				//Earnings per day
				System.out.println("paidDays : "+paidDays);
				System.out.println("salaryStracture : "+salaryStracture);
				double basic = (Double.parseDouble(salaryStracture.getBasic())/paidDays)*paidDays;
				double hra = (Double.parseDouble(salaryStracture.getHra())/paidDays)*paidDays;
				double conv = (Double.parseDouble(salaryStracture.getConveyance())/paidDays)*paidDays;
				double spl = (Double.parseDouble(salaryStracture.getSpecialAllowance())/paidDays)*paidDays;
				double medic = (Double.parseDouble(salaryStracture.getMedicalAllowance())/paidDays)*paidDays;
				double others = (Double.parseDouble(salaryStracture.getOthers())/paidDays)*paidDays;
				double totalEarnings =basic+hra+conv+spl+medic+others;
				System.out.println("totalEarnings : "+totalEarnings);

				SalaryStracture sal = new SalaryStracture();
				sal.setBasic(PayRollUtility.decilamFormat(basic+""));
				sal.setHra(PayRollUtility.decilamFormat(hra+""));
				sal.setConveyance(PayRollUtility.decilamFormat(conv+""));
				sal.setSpecialAllowance(PayRollUtility.decilamFormat(spl+""));
				sal.setMedicalAllowance(PayRollUtility.decilamFormat(medic+""));
				sal.setOthers(PayRollUtility.decilamFormat(others+""));
				sal.setTotalEarnigs(PayRollUtility.decilamFormat(totalEarnings+""));
				sal.setGrossSalary(salaryStracture.getGrossSalary());
				//Eranings per month
				double totalLop = 0;
				double totalInc = 0;
				System.out.println("lopDays : "+lopDays);
				System.out.println("incentiveDays : "+incentiveDays);
				if(lopDays > 0){

					double basicLop = (Double.parseDouble(salaryStracture.getBasic())/maxDay)*lopDays;
					double hraLop = (Double.parseDouble(salaryStracture.getHra())/maxDay)*lopDays;
					double convLop = (Double.parseDouble(salaryStracture.getConveyance())/maxDay)*lopDays;
					double splLop = (Double.parseDouble(salaryStracture.getSpecialAllowance())/maxDay)*lopDays;
					double medicLop = (Double.parseDouble(salaryStracture.getMedicalAllowance())/maxDay)*lopDays;
					double othersLop = (Double.parseDouble(salaryStracture.getOthers())/maxDay)*lopDays;

					totalLop = basicLop+hraLop+convLop+splLop+medicLop+othersLop;
					System.out.println("totalLop : "+totalLop);
					totalEarnings = totalEarnings - totalLop;
				}else if(incentiveDays > 0){

					double basicinc = (Double.parseDouble(salaryStracture.getBasic())/paidDays)*lopDays;
					double hrainc = (Double.parseDouble(salaryStracture.getHra())/paidDays)*lopDays;
					double convinc = (Double.parseDouble(salaryStracture.getConveyance())/paidDays)*lopDays;
					double splinc = (Double.parseDouble(salaryStracture.getSpecialAllowance())/paidDays)*lopDays;
					double medicinc = (Double.parseDouble(salaryStracture.getMedicalAllowance())/paidDays)*lopDays;
					double othersinc = (Double.parseDouble(salaryStracture.getOthers())/paidDays)*lopDays;

					totalInc = basicinc+hrainc+convinc+splinc+medicinc+othersinc;
					totalEarnings = totalEarnings+totalInc;
				}


				System.out.println("esiPfBonus : "+esiPfBonus);

				totalEarnings =Math.round(totalEarnings);

				System.out.println("totalEarnings : "+totalEarnings);
				//Deductions
				double ptSlab = 0.0;
				if(totalEarnings+(basic*(esiPfBonus.getBonus()/100)) > 1){
				
					ptSlab  = salaryRepository.getPT(String.valueOf(totalEarnings+(basic*(esiPfBonus.getBonus()/100))));
				}
				System.out.println("ptSlab : "+ptSlab);
				double pfAmt = 0;
				if(salaryStracture.isPfrequired()){

					pfAmt = basic*(esiPfBonus.getPf()/100);

					if(salaryStracture.isVoluntary()){

						String extra =  salaryStracture.getEmployeeCont();

						if(salaryStracture.isExcludingBase()){

							pfAmt = pfAmt+Double.parseDouble(extra);
						}else{

							pfAmt = Double.parseDouble(extra);
						}

					}
					if(totalEarnings < pfAmt){

						if(totalEarnings > pfAmt /4 && totalEarnings < pfAmt /2){
							pfAmt = pfAmt /4;
						}else if(totalEarnings > pfAmt/2 && totalEarnings < pfAmt / 3){
							pfAmt = pfAmt /2;
						}else if(totalEarnings > pfAmt/3){
							pfAmt = pfAmt /3;
						}
					}
				}
				System.out.println("pfAmt : "+pfAmt);
				double esiAmt = 0;
				if(salaryStracture.isEsirequired()){

					esiAmt = basic*(esiPfBonus.getEsi()/100);
				}
				System.out.println("esiAmt : "+esiAmt);
				double totalDedctions = pfAmt+esiAmt+ptSlab;
				System.out.println("totalDedctions : "+totalDedctions);

				sal.setTotalDesctions(PayRollUtility.decilamFormat(totalDedctions+""));
				totalDedctions =Math.round(totalDedctions);
				double netPay = totalEarnings - totalDedctions;

				sal.setIncentive(PayRollUtility.decilamFormat(totalInc+""));
				sal.setLop(PayRollUtility.decilamFormat(totalLop+""));
				sal.setNetPay(PayRollUtility.decilamFormat(netPay+""));
				sal.setEmployee(curEmp);
				sal.setMaxDays(maxDay+"");
				sal.setPaidDays(paidDays+"");
				sal.setPfAmt(PayRollUtility.decilamFormat(pfAmt+""));
				sal.setEsiAmt(PayRollUtility.decilamFormat(esiAmt+""));
				sal.setPtAmount(PayRollUtility.decilamFormat(ptSlab+""));

				salaryRepository.insertOrUpdatePaidSalaryInfo(curEmpID, String.valueOf(selectedMonths), selyear, sal);

				empSalStr.put(curEmpID, sal);
			}
		}

		System.out.println("empSalStr : "+empSalStr);
		return empSalStr;
	}
	
	public HashMap<String, String> getComputedSalary(String empId,String month,String year,String company,
			String dept,String unit,String design) throws Exception{
		
		return salaryRepository.getComputedSalary(empId, month, year, company, dept, unit, design);
	}

	@Override
	public void recoverAmount(String empId, String rowNo, double amount)
			throws BusinessException {
		
		salaryRepository.recoverAmount(empId, rowNo, amount);
		
	}
	
	/*public static void main(String[] args) {
		
		SalaryDAOImpl sd = new SalaryDAOImpl();
		
		try {
			HashMap<String, SalaryStracture> s = sd.computeSalaryForMonth("01-01-2013", "31-01-2013", "IP1024", "IP", "1", "AD", "2013", 01);
			System.out.println(s);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}*/
}
